<template>
  <div>
    <Header v-if="status == 0" :left="true" leftText="返回" title="返工执行明细" />
    <Header v-if="status == 1" :left="true" leftText="返回" title="返工验收明细" />
    <!-- 滑动区域，适应手机分辨率 -->
    <div class="textScroll" :style="{ bottom: bottomHeight ? '2rem' : '4rem' }">


      <van-field readonly class="formstyle" name="text" v-model="form.QualityDefectReviewID" label="问题产品处置单"
        placeholder="点击选择问题产品处置单" @click="cans2" />
      <van-field v-model="form.OrderMemo" readonly size="small" class="formstyle" center colon label="返工单描述"
        placeholder="请输入返工单描述" />





      <van-field readonly class="formstyle" name="picker" :value="valuepline" label="生产线" placeholder="点击选择产线" />

      <van-field class="formstyle" v-model="form.POrderID" name="生产订单" label="生产订单" placeholder="生产订单"
        @click.stop="getProductionOrder" />



      <van-field v-model="form.MaterialID" size="small" class="formstyle" center colon label="产品代码" :readonly="true"
        placeholder="请先扫描订单条码" />

      <van-field v-model="form.MaterialName" size="small" class="formstyle" center colon label="产品名称" :readonly="true"
        placeholder="请先扫描订单条码" />


      <van-field readonly class="formstyle" name="picker" v-model="valueteamName" label="班组" placeholder="点击选择班组" />


      <van-field readonly v-model="form.BatchID" size="small" class="formstyle" center colon label="生产批次"
        placeholder="请输入生产批次" />


      <van-field :readonly="true" v-model="CreateDatetimeP" size="small" class="formstyle" center colon label="生产日期"
        placeholder="请输入申请生产日期选择" />


      <van-field readonly v-model="showShift" required size="small" class="formstyle" center colon label="班次"
        placeholder="请输入班次" />

      <van-field readonly v-model="form.DealWithAmount" required size="small" class="formstyle" center colon label="待处理数量"
        placeholder="待处理数量" />
      <van-field readonly v-model="form.SampleAmount" required size="small" class="formstyle" center colon label="抽样数量"
        placeholder="请输入抽样数量" />


      <van-field v-model="employeeName" readonly required size="small" class="formstyle" center colon label="QC"
        placeholder="请输入QC" />
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">缺陷原因</NoticeBar>
      <van-field readonly style="font-weight: bold" v-model="form.ReworkReason" class="formstyle" rows="4" autosize
        label="缺陷原因" type="textarea" maxlength="150" placeholder="输入缺陷原因" show-word-limit />
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">返工方案</NoticeBar>
      <van-field required :readonly="true" size="small" class="formstyle" center colon :value="form.Operation"
        label="返工方案" placeholder="请输入返工方案" />
      <van-field readonly v-model="form.ReworkAoumt" required size="small" class="formstyle" center colon label="返工数量"
        placeholder="请输入返工数量" />
      <NoticeBar color="#4e4a67" background="#ffffff" style="margin-top: 5px; font-size: 15px; font-weight: bold">方案说明：
      </NoticeBar>
      <van-field style="font-weight: bold;border:1px solid #ccc!important;width: 95%;margin: 0 auto;"
        v-model="form.OperationTxt" class="formstyle" rows="4" autosize label="" type="textarea" maxlength="150"
        placeholder="" show-word-limit readonly />

      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">执行信息</NoticeBar>
      <Field readonly class="Field" label="返工操作人" v-model="user.employeeName" />
      <!-- <Field required :readonly="form.CompleteFlag" class="Field" label="QC班长" v-model="sendData.QCLeader"
        placeholder="输入QC班长" /> -->
      <Field required readonly class="Field" name="picker" :value="sendData.ProductionLeader" label="生产主任"
        placeholder="输入生产主任" @click="showPickerEmployee = (form.status2 == 0)" />
      <van-popup v-model="showPickerEmployee" position="bottom">
        <van-picker show-toolbar :columns="columnsEmployee" @confirm="onConfirmEmployee"
          @cancel="showPickerEmployee = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.EmployeeName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <Field required class="Field" label="返工完成备注" :readonly="form.CompleteFlag" v-model="sendData.ReworkMemo"
        placeholder="输入返工完成备注" />
      <div v-if="status == 1">
        <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
          left-icon="description">验收信息</NoticeBar>
        <!-- 显示验收信息-->
        <Field readonly v-model="user.employeeName" size="small" class="Field" center colon label="品管确认" />

        <Field required readonly class="Field" name="picker" v-model="sendData.QCLeader" label="品管领班确认"
          placeholder="输入品管领班" @click="showPickerEmployee1 = true" />
        <van-popup v-model="showPickerEmployee1" position="bottom">
          <van-picker show-toolbar :columns="columnsEmployee1" @confirm="onConfirmEmployee1"
            @cancel="showPickerEmployee1 = false">
            <template #option="option">
              <div style="
                  display: flex;
                  flex-direction: column;
                  align-items: center;
                ">
                <div>{{ option.EmployeeName }}</div>
              </div>
            </template>
          </van-picker>
        </van-popup>
        <Field required :readonly="form.Comfirmed" class="Field" label="合格数量" v-model="sendData.GoodAmount" rows="1"
          autosize type="textarea" placeholder="输入合格数量" />
        <Field readonly class="Field" label="废品数量" :value="Number(form.ReworkAoumt) - Number(sendData.GoodAmount)"
          rows="1" autosize type="textarea" placeholder="自动计算废品数量" />
        <Field :readonly="form.Comfirmed" v-model="sendData.ComfiredMemo" size="small" class="Field" center colon
          label="确认备注" />
        <Field v-model="nowDate" v-if="!form.Comfirmed" :readonly="true" size="small" class="Field" center colon
          label="验收时间" />
        <Field v-model="form.ConfirmDatetime" v-if="form.Comfirmed" :readonly="true" size="small" class="Field" center
          colon label="验收时间" />
      </div>


      <van-row gutter="2" style="margin-top: 40px;" v-if="btnStartShow == 0">
        <van-col span="24">
          <van-button :block="true" round class="buttonColor2" type="primary" color="#138087" text="开始执行"
            @click="startAdjust()" />
        </van-col>
      </van-row>
      <van-row gutter="2" style="margin-top: 40px;" v-if="btnStartShow == 1">
        <van-col span="24">
          <van-button :block="true" round class="buttonColor2" type="primary" color="#138087" text="执行保存"
            @click="startAdjust2()" />
        </van-col>
      </van-row>

      <!-- 底部按钮 -->
      <van-row gutter="2" style="margin-top: 40px;">
        <van-col span="12">
          <van-button :block="true" style="width: 70%;;margin-left: 10%" round @click="
            finishUnAcceptRework( Number(form.ReworkAoumt) - Number(sendData.GoodAmount))
            " v-if="status == 1 && btnAcceptShow" class="buttonColor2" type="warning" text="验收不合格" />
        </van-col>
        <van-col span="12">
          <van-button :block="true" style="width: 70%;;margin-left: 10%" round @click="
            finishAcceptRework( Number(form.ReworkAoumt) - Number(sendData.GoodAmount))
            " v-if="status == 1 && btnAcceptShow" class="buttonColor2" type="primary" color="#138087" text="验收合格" />
        </van-col>
      </van-row>
      <br />
      <br />
      <br />
      <br />
      <br />
    </div>
    <!-- 底部按钮 -->
  </div>
</template>
<script>
import {
  Icon,
  NoticeBar,
  Button,
  Row,
  Tag,
  Checkbox,
  Pagination,
  popup,
  Loading,
  Popup,
  Panel,
  ImagePreview,
  Toast,
  tab,
  tabs,
  Divider,
  Image as VanImage,
  Field,
  CellGroup,
  Cell,
  Picker,
  Uploader,
  Dialog,
  Col,
  RadioGroup,
  Radio,
  DatetimePicker,
} from "vant";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { _httpClient } from "@/libs/apisie";
import { storage } from "@/libs/utils";
import {
  removeToken,
  getToken,
  setBaseApiFrefix,
  getBaseApiFrefix,
} from "@/libs/auth";

Vue.use(DatetimePicker);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(tab);
Vue.use(tabs);
Vue.use(Button);
Vue.use(Col);
Vue.use(Row);
Vue.use(Icon);
Vue.use(VanImage);
Vue.use(Divider);
Vue.use(Checkbox);
Vue.use(Pagination);
Vue.use(Panel);
Vue.use(Dialog);
Vue.use(Picker);
Vue.use(popup);
Vue.use(Uploader);
Vue.use(Loading);
Vue.use(Field);
Vue.use(RadioGroup);
Vue.use(Radio);
import Header from "@/components/header.vue";
export default {
  name: "reworkExecutionItem",
  components: {
    Button,
    NoticeBar,
    Header,
    ImagePreview,
    Icon,
    Row,
    tab,
    popup,
    Popup,
    tabs,
    Tag,
    VanImage,
    Toast,
    Divider,
    Field,
    CellGroup,
    Cell,
    Uploader,
    Picker,
    Dialog,
    Col,
    RadioGroup,
    Radio,
  },
  data() {
    return {
      valuepline: null,
      valueteamName: null,
      CreateDatetimeP: null,
      showShift: null,
      employeeName: null,
      minDate: new Date(2023, 0, 1),
      maxDate: new Date(2050, 11, 31),
      nowDate: null,
      btnLoading: false,
      winName: "", //窗口名
      user: [], //当前登录用户
      btnStartShow: -1, //开始返工按钮权限
      screenWidth: 0,
      columnsEmployee: [],
      columnsEmployee1: [],
      columnsshift: [],
      columnsteamId: [],
      columnspline: [
        { plineId: "返修", plineName: "返修" },
        { plineId: "挑选", plineName: "挑选" },
        { plineId: "其他", plineName: "其他" },
      ],
      showPickerEmployee: false,
      showPickerEmployee1: false,
      item: {},
      EmployeeName: "",
      EmployeeName1: "",
      valuepShiftName: "",
      EmployeeID: "",
      showPickerpline: false,
      //是否显示人员
      showEmployee: false,
      sendData: {},
      showPickerdatetime: false,
      showPickerEndDatetime: false,
      status: "",
      btnAcceptShow: false,
      bottomHeight: false,
    };
  },
  created: function () {
    let oldHight = api.winWidth;
    this.screenWidth = oldHight;
    this.user = JSON.parse(storage.get("user"));
    this.user.userId = this.user.userName;
    //页面赋值
    this.form = api.pageParam.item;
    // alert(JSON.stringify(this.form))
    this.status = api.pageParam.status;
    this.sendData.ProductionLeader = this.form.ProductionLeader;
    if (this.form.Comfirmed) {
      this.sendData.QCLeader = this.form.QCLeader;
    } else {
      this.sendData.QCLeader = ""
    }

    this.getAbnMessage();


    // this.getshift();
    // this.getteam();

    //this.sendData.GoodAmount =0;
    //获取员工列表
    /* this.getEmployeeID(); */
  },
  mounted() {
    this.getNowTime(); //进入页面调用该方法获取当前时间
    clearInterval(myTimeDisplay); //销毁之前定时器
    var myTimeDisplay = setInterval(() => {
      this.getNowTime(); //每秒更新一次时间
    }, 1000);
    this.initPage();

    // this.sendData.QCLeader=""
  },
  destroyed() {
    clearInterval(this.nowtimer);
    this.nowDate = null;
  },
  methods: {
    async getAbnMessage() {

      // alert(JSON.stringify(this.form))
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/QualityDefectReview/GetEntity?id=" + this.form.QualityDefectReviewID
        )

        // alert(JSON.stringify(res))
        if (res.Data != null) {
          this.valuepline = res.Data.PLineID;
          this.form.POrderID = res.Data.POrderID;
          this.form.MaterialID = res.Data.MaterialID;
          this.form.MaterialName = res.Data.MaterialName;
          this.form.TeamID = res.Data.TeamID;
          this.form.BatchID = res.Data.BatchID;
          this.CreateDatetimeP = res.Data.CreateDatetime
          let res2 = await _httpClient.get(
            _httpClient.getApiPrefix() + "/Team/GetList?TeamID=" + res.Data.TeamID
          )
          // alert(JSON.stringify(res2))
          this.valueteamName = res2.Data[0].TeamName;

          // alert(_httpClient.getApiPrefix()+"/ProductionShift/GetList?PShiftID="+this.form.PShiftID)

          let res3 = await _httpClient.get(
            _httpClient.getApiPrefix() + "/ProductionShift/GetList?PShiftID=" + this.form.PShiftID
          )
          this.showShift = res3.Data[0].PShiftName

        }

        // alert( _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID="+this.form.Creator)
        let res4 = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.Creator
        )

        // alert("res"+JSON.stringify(res4))/
        if (res4.Data.length > 0) {
          this.employeeName = res4.Data[0].EmployeeName
        }


        // alert(JSON.stringify(res))
      } catch (e) {
        alert("--" + JSON.stringify(e))
      }

    },
    getNowTimeplus() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },

    //002 
    async sendmessageinit() {
      try {
        // alert(JSON.stringify(this.form));
        let _this = this;

        let eventDescription = "生产返工单";
        let eventDatetime = _this.getNowTimeplus();
        let eventTypeID = "N3";
        let eventID = "RWK02";
        let messageContent = "生产返工单";
        let msgContentTypeID = "RW002";
        let pLineID = _this.form.PLineID;
        let machineID = _this.form.MaterialID;
        let pShiftID = "";
        let teamID = "";
        let pOrderID = _this.form.POrderID;
        let productionBarcode = "";
        let materialBarcode = "";
        let relatedEmployee = "";
        let messageStatus = "";
        let processBatchID = "";
        let beginDatetime = _this.getNowTimeplus();
        let sendFinished = false;
        let closed = false;

        msgContentTypeID = "RW002";
        eventID = "RWK02";
        //eventDescription = "生产返工单:已经被:" + _this.user.employeeName + "执行完毕，请尽快组织返工确认验收！";

        eventDescription = "生产订单" + _this.form.POrderID + "在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工，返工单已被接收，相关岗位知悉!";
        messageContent = "生产订单" + _this.form.POrderID + "在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工，返工单已被接收，相关岗位知悉!";
        // eventDescription = "生产返工单:" ;
        // messageContent = "生产订单";

        let bodysss = {
          eventDescription: eventDescription,
          eventDatetime: eventDatetime,
          eventTypeID: eventTypeID,
          eventID: eventID,
          messageContent: messageContent,
          msgContentTypeID: msgContentTypeID,
          factoryID: "TC00",
          pLineID: pLineID,
          machineID: machineID,
          pShiftID: pShiftID,
          teamID: teamID,
          pOrderID: pOrderID,
          productionBarcode: productionBarcode,
          materialBarcode: materialBarcode,
          relatedEmployee: relatedEmployee,
          messageStatus: messageStatus,
          processBatchID: processBatchID,
          beginDatetime: beginDatetime,
          sendFinished: sendFinished,
          closed: closed
        };

        //alert(JSON.stringify(bodysss));
        try {
          let res = await _httpClient.post(
            _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
            {
              body: bodysss
            }
          );
          //alert(JSON.stringify(res));
          if (res.Message == null) {
            Toast.clear();
            Toast.success("发送成功");
            api.sendEvent({
              name: "reloadReworkExecution",
            });
            api.closeWin();
          } else {
            Toast.clear();
            Toast.fail("发送失败");
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }
      } catch (error) {
        alert(error);
      }

    },
    //003
    async sendmessage() {
      try {
        // alert(JSON.stringify(this.form));
        let _this = this;

        let eventDescription = "";
        let eventDatetime = _this.getNowTimeplus();
        let eventTypeID = "N3";
        let eventID = "";
        let messageContent = "";
        let msgContentTypeID = "";
        let pLineID = _this.form.PLineID;
        let machineID = _this.form.MaterialID;
        let pShiftID = "";
        let teamID = "";
        let pOrderID = _this.form.POrderID;
        let productionBarcode = "";
        let materialBarcode = "";
        let relatedEmployee = "";
        let messageStatus = "";
        let processBatchID = "";
        let beginDatetime = _this.getNowTimeplus();
        let sendFinished = false;
        let closed = false;

        msgContentTypeID = "RW003";
        eventID = "RWK03";
        eventDescription = "生产返工单:已经被:" + _this.user.employeeName + "执行完毕，请尽快组织返工确认验收！";
        messageContent = "生产订单" + "在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工,请尽快执行返工单的确认验收！";
        // eventDescription = "生产返工单:" ;
        // messageContent = "生产订单";

        let bodysss = {
          eventDescription: eventDescription,
          eventDatetime: eventDatetime,
          eventTypeID: eventTypeID,
          eventID: eventID,
          messageContent: messageContent,
          msgContentTypeID: msgContentTypeID,
          factoryID: "TC00",
          pLineID: pLineID,
          machineID: machineID,
          pShiftID: pShiftID,
          teamID: teamID,
          pOrderID: pOrderID,
          productionBarcode: productionBarcode,
          materialBarcode: materialBarcode,
          relatedEmployee: relatedEmployee,
          messageStatus: messageStatus,
          processBatchID: processBatchID,
          beginDatetime: beginDatetime,
          sendFinished: sendFinished,
          closed: closed
        };

        //alert(JSON.stringify(bodysss));
        try {
          let res = await _httpClient.post(
            _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
            {
              body: bodysss
            }
          );
          //alert(JSON.stringify(res));
          if (res.Message == null) {
            Toast.clear();
            Toast.success("发送成功");
            api.sendEvent({
              name: "reloadReworkExecution",
            });
            api.closeWin();
          } else {
            Toast.clear();
            Toast.fail("发送失败");
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }
      } catch (error) {
        alert(error);
      }

    },
    //004 005
    async sendmessageplus(val) {
      try {
        // alert(JSON.stringify(this.form));
        let _this = this;

        let eventDescription = "";
        let eventDatetime = _this.getNowTimeplus();
        let eventTypeID = "N3";
        let eventID = "";
        let messageContent = "";
        let msgContentTypeID = "";
        let pLineID = _this.form.PLineID;
        let machineID = _this.form.MaterialID;
        let pShiftID = "";
        let teamID = "";
        let pOrderID = _this.form.POrderID;
        let productionBarcode = "";
        let materialBarcode = "";
        let relatedEmployee = "";
        let messageStatus = "";
        let processBatchID = "";
        let beginDatetime = _this.getNowTimeplus();
        let sendFinished = false;
        let closed = false;



        if (val) {
          eventDescription = "生产返工单:已经被:" + _this.user.employeeName + "确认验收通过，请知悉";

          msgContentTypeID = "RW004";
          eventID = "RWK04";
          messageContent = "生产订单" + pOrderID + "在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工，返工单验收合格，请知悉！";
        }
        else {
          eventDescription = "生产返工单:" + (new Date().toLocaleString()) + "由" + _this.user.employeeName + "验收时没有通过，请继续执行返工！";

          msgContentTypeID = "RW005";
          eventID = "RWK05";
          messageContent = "生产订单" + pOrderID + ",在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工，返工单验收时候没有通过，请继续按照要求执行返工！";;

        }

        // eventDescription = "生产返工单:" ;
        // messageContent = "生产订单";

        let bodysss = {
          eventDescription: eventDescription,
          eventDatetime: eventDatetime,
          eventTypeID: eventTypeID,
          eventID: eventID,
          messageContent: messageContent,
          msgContentTypeID: msgContentTypeID,
          factoryID: "TC00",
          pLineID: pLineID,
          machineID: machineID,
          pShiftID: pShiftID,
          teamID: teamID,
          pOrderID: pOrderID,
          productionBarcode: productionBarcode,
          materialBarcode: materialBarcode,
          relatedEmployee: relatedEmployee,
          messageStatus: messageStatus,
          processBatchID: processBatchID,
          beginDatetime: beginDatetime,
          sendFinished: sendFinished,
          closed: closed
        };

        //alert(JSON.stringify(bodysss));
        try {
          let res = await _httpClient.post(
            _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
            {
              body: bodysss
            }
          );
          //alert(JSON.stringify(res));
          if (res.Message == null) {
            Toast.clear();
            Toast.success("发送成功");
            api.sendEvent({
              name: "reloadReworkExecution",
            });
            api.closeWin();
          } else {
            Toast.clear();
            Toast.fail("发送失败");
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }
      } catch (error) {
        alert(error);
      }

    },
    //获取员工列表
    async getEmployeeID() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW21"
        );
        if (res.HttpCode === "200") {
          //Toast.fail(JSON.stringify("进入成功"));
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    //获取员工列表
    //GW26-->GW35,edit by zhouweidong on 2023-11-6
    async getEmployeeID1() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW35"
        );
        if (res.HttpCode === "200") {
          //Toast.fail(JSON.stringify("成功进入"));
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取员工列表
    async getEmployeeID2() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW11"
        );
        let res2 = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW08"
        );
        if (res.HttpCode === "200" && res2.HttpCode === "200") {
          //Toast.fail(JSON.stringify("成功进入"));
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          let temp2 = res2.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee1.push(item);
          });

          temp2.forEach((item) => {
            _this.columnsEmployee1.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmEmployee(value, index) {
      this.sendData.ProductionLeader = this.columnsEmployee[index].EmployeeName;
      this.form.ProductionLeader = this.columnsEmployee[index].EmployeeName;
      this.EmployeeName = this.columnsEmployee[index].EmployeeName;
      this.showPickerEmployee = false;
    },
    onConfirmEmployee1(value, index) {
      this.sendData.QCLeader = this.columnsEmployee1[index].EmployeeName;
      this.form.QCLeader = this.columnsEmployee1[index].EmployeeName;
      this.EmployeeName1 = this.columnsEmployee1[index].EmployeeName;
      this.showPickerEmployee1 = false;
    },
    onConfirmpline(value, index) {
      this.sendData.Operation = this.columnspline[index].plineId;
      this.showPickerpline = false;
    },
    initPage() {
      if (this.status == 0) {
        this.getEmployeeID();
        this.getEmployeeID1();
        //返工操作
        if (this.form.status2 == 0) {
          //若已完成
          this.sendData = this.form;
          this.btnStartShow = 0;
          this.bottomHeight = true;
          this.sendData.ProductionLeader = ""
        }

        if (this.form.status2 == 1) {
          //若已完成
          this.sendData = this.form;
          this.btnStartShow = 1;
          this.bottomHeight = true;
        }
        if (this.form.status2 == 2) {
          this.sendData.Reworker = this.user.userId;
          this.btnStartShow = 2;
          this.sendData.ReworkMemo =
            this.getNowTime() +
            "返工完成:" +
            this.user.employeeName +
            "完成返工操作!";
          this.bottomHeight = false;
        }
      } else {
        this.getEmployeeID2();
        //验收操作
        if (this.form.Comfirmed) {
          //若已完成验收
          this.sendData = this.form;
          this.btnAcceptShow = false;
          this.nowDate = this.form.ConfirmDatetime;
          this.bottomHeight = true;
        } else {
          this.sendData = this.form;
          this.sendData.ComfirmMan = this.user.userId;
          this.btnAcceptShow = true;
          this.sendData.ComfiredMemo =
            this.getNowTime() +
            "返工验收人:" +
            this.user.employeeName +
            "完成验收操作!";
          this.bottomHeight = false;
        }
      }
    },
    checkShowPickerStartDatetime() {
      if (this.form.CompleteFlag) {
        //若已完成
        this.showPickerdatetime = false;
      } else {
        this.showPickerdatetime = true;
      }
    },
    checkShowPickerEndDatetime() {
      if (this.form.CompleteFlag) {
        //若已完成
        this.showPickerEndDatetime = false;
      } else {
        this.showPickerEndDatetime = true;
      }
    },
    onConfirmdatetime(time) {
      this.tempTime = time;
      //date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); // 时区补偿
      this.sendData.ReworkBeginDatetime = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showPickerdatetime = false;
    },
    onConfirmEndDatetime(time) {
      this.tempTime = time;
      //date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); // 时区补偿
      this.sendData.ReworkEndDatetime = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showPickerEndDatetime = false;
    },
    //获取班组信息
    async getteam() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() +
          "/Team/GetList?FactoryID=" +
          _this.form.FactoryID
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            teamID: item.TeamID,
            teamName: item.TeamName,
          }));
          _this.columnsteamId = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取班次信息
    // async getshift() {
    //   let _this = this;
    //   try {
    //     let res = await _httpClient.get(
    //       _httpClient.getApiPrefix() +
    //       "/ProductionShift/GetList?factoryID=" +
    //       _this.form.FactoryID
    //     );
    //     if (res.HttpCode === "200") {
    //       for (let index = 0; index < res.Data.length; index++) {
    //         if (res.Data[index].Actived == false) {
    //           delete res.Data[index];
    //         }
    //       }
    //       let shiftMap = res.Data.map((item) => ({
    //         pShiftName: item.PShiftName,
    //         pShiftID: item.PShiftID,
    //       }));
    //       _this.columnsshift = shiftMap;
    //     }
    //   } catch (e) {
    //     Toast.fail(JSON.stringify(e));
    //   }
    // },
    showShiftIDName(pShiftID) {
      var pShiftName;
      this.columnsshift.forEach((item) => {
        if (item.pShiftID === pShiftID) {
          pShiftName = item.pShiftName;
        }
      });
      return pShiftName;
    },
    showTeamIDName(teamID) {
      let teamName = teamID;
      this.columnsteamId.forEach((item) => {
        if (item.teamID === teamID) {
          teamName = item.teamName;
        }
      });
      return teamName;
    },
    //开始返工
    // startRepair() {
    //   Dialog.confirm({
    //     title: "提示",
    //     message: "是否确认已完成返工操作?",
    //     theme: "round-button",
    //   })
    //     .then(() => {
    //       //点击确定，继续执行后续操作
    //       this.startAdjust();
    //     })
    //     .catch(() => { });
    // },
    //完成返工
    async startAdjust() {
      // alert(1);
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/ReworkOrder/SaveEntity",
          {

            body: {
              id: _this.form.Id,
              Reworker: _this.sendData.Reworker,
              QCLeader: _this.sendData.QCLeader,
              ProductionLeader: _this.sendData.ProductionLeader,
              ReworkBeginDatetime: _this.sendData.ReworkBeginDatetime,
              ReworkEndDatetime: _this.sendData.ReworkEndDatetime,
              Operation: _this.sendData.Operation,
              ReworkMemo: _this.sendData.ReworkMemo,
              Received: true,
              ReceivedDatetime: new Date()
            },
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          //返工失败
          Toast.clear();
          Toast.success("保存成功！");
          _this.sendmessageinit();
          // api.sendEvent({
          //   name: "reloadReworkExecution",
          // });
          // api.closeWin();
        } else {
          Toast.clear();
          Toast.fail("保存失败！");
        }
      } catch (e) {
        //alert(JSON.stringify(e));
        Toast.fail(JSON.stringify(e));
      }
    },
    async startAdjust2() {
      // alert(1);
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/ReworkOrder/SaveEntity",
          {

            body: {
              id: _this.form.Id,
              Reworker: _this.sendData.Reworker,
              QCLeader: _this.sendData.QCLeader,
              ProductionLeader: _this.sendData.ProductionLeader,
              ReworkBeginDatetime: _this.sendData.ReworkBeginDatetime,
              ReworkEndDatetime: _this.sendData.ReworkEndDatetime,
              Operation: _this.sendData.Operation,
              ReworkMemo: _this.sendData.ReworkMemo,
              CompleteFlag: true,
            },
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          //返工失败
          Toast.clear();
          Toast.success("保存成功！");
          _this.sendmessage();
          // api.sendEvent({
          //   name: "reloadReworkExecution",
          // });
          // api.closeWin();
        } else {
          Toast.clear();
          Toast.fail("保存失败！");
        }
      } catch (e) {
        //alert(JSON.stringify(e));
        Toast.fail(JSON.stringify(e));
      }
    },
    //开始返工
    finishAcceptRework(val) {
      Dialog.confirm({
        title: "提示",
        message: "是否确认已完成返工验收?",
        theme: "round-button",
      })
        .then(() => {
          //点击确定，继续执行后续操作
          this.finishAccept(val);
        })
        .catch(() => { });
    },

    finishUnAcceptRework(val) {
      Dialog.confirm({
        title: "提示",
        message: "是否确认返工不合格?",
        theme: "round-button",
      })
        .then(() => {
          //点击确定，继续执行后续操作
          this.finishUnAccept(val);
        })
        .catch(() => { });
    },

    async finishUnAccept(val) {
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/ReworkOrder/SaveEntity",
          {
            body: {
              id: _this.form.Id,
              ComfirmMan: _this.sendData.ComfirmMan,
              ComfiredMemo: _this.sendData.ComfiredMemo,
              ConfirmDatetime: _this.getNowTime(),
              QCLeader: _this.sendData.QCLeader,
              GoodAmount: _this.sendData.GoodAmount,
              BadAmount: val,
              CompleteFlag: false,
            },
          }
        );
        if (res.Message != null) {
          //返工失败
          Toast.clear();
          Toast.fail("保存失败,请联系管理员！");
        } else {
          //打卡成功
          Toast.clear();
          //Toast.success("保存成功！");
          _this.sendmessageplus(false);
          // api.sendEvent({
          //   name: "reloadReworkAccept",
          // });
          // api.closeWin();
        }
      } catch (e) {
        //alert(JSON.stringify(e));
        alert(JSON.stringify(e));
      }
    },

    //完成验收
    async finishAccept(val) {
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "Loading...",
      });
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/ReworkOrder/SaveEntity",
          {
            body: {
              id: _this.form.Id,
              ComfirmMan: _this.sendData.ComfirmMan,
              ComfiredMemo: _this.sendData.ComfiredMemo,
              ConfirmDatetime: _this.getNowTime(),
              QCLeader: _this.sendData.QCLeader,
              GoodAmount: _this.sendData.GoodAmount,
              BadAmount: val,
              Comfirmed: true,
            },
          }
        );
        if (res.Message != null) {
          //返工失败
          Toast.clear();
          Toast.fail("保存失败,请联系管理员！");
        } else {
          //打卡成功
          Toast.clear();
          //Toast.success("保存成功！");
          _this.sendmessageplus(true);
          // api.sendEvent({
          //   name: "reloadReworkAccept",
          // });
          // api.closeWin();
        }
      } catch (e) {
        //alert(JSON.stringify(e));
        alert(JSON.stringify(e));
      }
    },


    // 获取当前时间
    getNowTime() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      this.nowDate = dateTime;
      return dateTime;
    },
  },
};
</script>
<style>
body {
  background-color: White;
}

.pic {
  width: 100%;
  text-align: center;
}

.clickbtn {
  width: 1;
  margin: 5px 10px;
  line-height: 45px;
  border: 1px #ccc dashed;
  text-align: center;
}

.buttonColor {
  background-color: #ff9933;
  border-color: #ff9933;
}

.buttonColor2 {
  background-color: #1076c0;
  border-color: #1076c0;
}

.message {
  font-size: 15px;
  margin-top: 5px;
  margin-left: -10px;
  font-weight: bold;
}

.divStyle {
  border: 1px solid #dcdcdc;
  border-top-width: 3px;
  border-left-width: 3px;
  margin-left: 5px;
  margin-right: 4px;
  margin-top: 4px;
}

.pagination {
  position: fixed;
  bottom: 15px;
  width: 300px;
  margin-left: 10%;
  color: rgb(0, 0, 255);
  text-align: center;
}

.divMedia {
  margin-top: 0px;
  height: 230px;
  border: solid #dcdcdc;
  margin-left: 5px;
  margin-right: 15px;
  border-top-width: 4px;
  border-left-width: 4px;
  border-right-width: 1px;
  border-bottom-width: 1px;
}

.divMedia2 {
  margin-top: 0px;
  height: 160px;
  border: solid #dcdcdc;
  margin-left: 5px;
  margin-right: 15px;
  border-top-width: 4px;
  border-left-width: 4px;
  border-right-width: 1px;
  border-bottom-width: 1px;
}

.button {
  position: fixed;
  left: 5px;
  right: 5px;
  bottom: 24px;
  width: 100%;
  height: 30px;
  font-size: 12px;
}

.divMessage {
  margin-top: 0px;
  border: solid #dcdcdc;
  margin-left: 5px;
  margin-right: 15px;
  border-top-width: 4px;
  border-left-width: 4px;
  border-right-width: 1px;
  border-bottom-width: 1px;
}

.Field {
  font-weight: bold;
  font-size: 15px;
  color: #9c8e8e;
  height: 45px;
}

.textScroll {
  display: inline-block;
  position: fixed;
  top: 5rem;
  overflow: scroll;
  right: 0;
  width: 100%;
  z-index: 1;
}
</style>
